package org.wmq.housewebadmin.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wmq.housemodel.entity.Facility;
import org.wmq.housemodel.entity.Result;
import org.wmq.housewebadmin.service.FacilityService;

import java.util.List;

@RestController
@RequestMapping("/admin/facility")
@RequiredArgsConstructor
public class FacilityController {
    private final FacilityService facilityService;

    @GetMapping("/list")
    public Result<List<Facility>> getFacilityList(@RequestParam(required = false) Byte type){
        return Result.ok(this.facilityService.getList(type));
    }

    @PostMapping("/saveOrUpdate")
    public Result<Void> saveOrUpdateFacility(@RequestBody Facility facility){
        return this.facilityService.saveOrUpdate(facility);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteById(@PathVariable Long id){
        if (this.facilityService.deleteById(id) == true){
            return Result.ok();
        }else{
            return Result.error("删除失败");
        }
    }
}
